package cn.yunsenlin.formula.cloud.group;

import cn.yunsenlin.formula.cloud.mysql.mapper.generator.TbGroupMapper;
import cn.yunsenlin.formula.cloud.responsibility.ResponseResponsibilityHandler;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;

/**
 * 检查当前计算组是否存在
 */
@Service
public class GroupExistRRH extends ResponseResponsibilityHandler {
    private final TbGroupMapper tbGroupMapper;

    @SuppressWarnings("all")
    public GroupExistRRH(TbGroupMapper tbGroupMapper) {
        this.tbGroupMapper = tbGroupMapper;
    }

    @Override
    protected Object doHandler(HttpServletResponse response, Object object) {
        return null;
    }

    @Override
    protected boolean continueAble(HttpServletResponse response, Object object) {
        int groupId = (int) object;
        boolean r =  tbGroupMapper.selectByPrimaryKey(groupId)!=null;
        if(!r){
            response.setStatus(404);
        }
        return r;
    }
}
